class SessionsController < ApplicationController

  layout 'login'

  def new
  end

  def create

    user = User.find_by_name(params[:name])

    if user && user.authenticate(params[:password])
      session[:user_id] = user.id
      redirect_to cpanel_root_path, notice: 'login success'
    else
      flash[:notice] = "login failed"
      render 'new'
    end
  end

  def destroy
    session[:user_id] = nil
    redirect_to login_path, notice: 'quit success'
  end
end
